// pages/homework/teacherUserinfo/teacherUseringo.js
import httpss from '../../../utils/request2.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo: {},
  },
  logout() {
    wx.showModal({
      title: '提示',
      content: '确定要退出登录吗？',
      success: (res) => {
        if (res.confirm) {
          wx.removeStorageSync('token')
          wx.removeStorageSync('studentToken')
          wx.showToast({
            title: '已退出登录',
            icon: 'success'
          })
          console.log('执行了');

          wx.reLaunch({
            url: '/pages/homework/login/login',
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  async onShow() {

    try {
      let phoneNumber = wx.getStorageSync('username')
      let phoneStr = String(phoneNumber);
      let res = await httpss({
        url: '/open/system/getTeacherByNumber',
        method: 'get',
        data: { phone: phoneStr },
        header: { "content-type": "application/json;charset=UTF-8" }
      })
      if (res && res.data.code == 200) {
        let teacherUserInfo = res.data.data
        teacherUserInfo.gradeListStr = teacherUserInfo.gradeList.join(',');
        teacherUserInfo.classListStr = teacherUserInfo.classList.join(',');
        teacherUserInfo.teacherRoleStr = teacherUserInfo.teacherRole.join(',');
        if (teacherUserInfo) {
          this.setData({
            userinfo: teacherUserInfo
          });
        }
        wx.setStorageSync('teacherUserInfo', teacherUserInfo);
      } else {
        wx.showModal({
          title: '提示',
          content: '登录状态失效，请重新登录',
          showCancel: false,
          success: () => {
            wx.reLaunch({ url: '/pages/homework/login/login' });
          }
        });
      }
    } catch (e) {
      console.error('onShow error:', e)
    }
    wx.hideTabBar({ animation: false });
    if (this.getTabBar && this.getTabBar()) {
      this.getTabBar().refreshTabBar(); 
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})